package view;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import rmi.Me;

/**
 * @author REMY Timothée and CARTIER Arthur
 *
 */
public class AddFriendFrame extends JFrame {
	public class OkOnClick implements ActionListener {

		@SuppressWarnings("unused")
		@Override
		public void actionPerformed(final ActionEvent e) {
			if (pseudo.getText().length() == 0) {
				final JOptionPane warning = new JOptionPane();
				JOptionPane.showMessageDialog(null,
						"Warning:\nNick name have to be not null", "Warning",
						JOptionPane.INFORMATION_MESSAGE, null);
			} else {
				final JOptionPane info = new JOptionPane();
				JOptionPane.showMessageDialog(getParent(),
						"Friend has been successful added", "Add friend",
						JOptionPane.INFORMATION_MESSAGE, null);
			}
		}
	}

	/**
	 * 
	 */
	private static final long serialVersionUID = 5073008803927230117L;
	private JTextField pseudo;
	private JTextField ip;
	private JTextField port;
	private JButton ok;

	Me me;

	public AddFriendFrame(final Me me) {
		super();
		this.me = me;
		final Dimension tailleEcran = Toolkit.getDefaultToolkit()
				.getScreenSize();
		setLayout(new GridLayout(7, 1));
		this.setSize(new Dimension(200, 200));
		setVisible(true);
		setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
		this.setLocation((tailleEcran.width - this.getSize().width) / 2,
				(tailleEcran.height - this.getSize().height) / 2);
	}

	public JTextField getIp() {
		return ip;
	}

	public JButton getOk() {
		return ok;
	}

	public JTextField getPort() {
		return port;
	}

	public JTextField getPseudo() {
		return pseudo;
	}

	public void initFrame() {
		final JLabel text1 = new JLabel("Enter the nickname");
		final JLabel text2 = new JLabel("Enter ip address");
		final JLabel text3 = new JLabel("Enter port");
		pseudo = new JTextField();
		ip = new JTextField();
		port = new JTextField();
		ok = new JButton("OK");
		this.add(text1);
		this.add(pseudo);
		this.add(text2);
		this.add(ip);
		this.add(text3);
		this.add(port);
		this.add(ok);
		ok.addActionListener(new OkOnClick());
		this.repaint();

	}

	public void setIp(final JTextField ip) {
		this.ip = ip;
	}

	public void setOk(final JButton ok) {
		this.ok = ok;
	}

	public void setPort(final JTextField port) {
		this.port = port;
	}

	public void setPseudo(final JTextField pseudo) {
		this.pseudo = pseudo;
	}

}
